package models

import "time"

// 服务表
type Services struct {
	//服务ID	主键
	ServiceID int `json:"service_id" orm:"pk;auto"`
	//服务名称
	ServiceName string `json:"service_name"`
	//服务状态
	ServiceStatus string `json:"service_status"`
	//客户ID，外键关联到Customers表的CustomerID
	//多对多(可以在销售订单中使用这个生成的关系表)
	Customers []*Customers `json:"customers" orm:"rel(m2m)"`
	//服务描述
	ServiceDescribe string `json:"service_describe"`
	//创建时间
	CreateTime time.Time `json:"create_time" orm:"auto_now_add"`
	//反向一对多
	SalesOrders []*SalesOrders `json:"sales_orders" orm:"reverse(many)"`
}

func (service *Services) UserToRespDesc() interface{} {
	customers := service.Customers[0]
	contacts := customers.Contacts

	respInfo := map[string]interface{}{

		"service_id":                 service.ServiceID,
		"service_name":               service.ServiceName,
		"service_status":             service.ServiceStatus,
		"customer_id":                customers.CustomerID,
		"customer_name":              customers.CustomerName,
		"contact_id":                 contacts.ContactID,
		"contact_name":               contacts.ContactName,
		"contact_info":               contacts.ContactInfo,
		"customers_address":          customers.CustomersAddress,
		"customers_address_add_time": customers.AddTime.Format("2006-01-02 15:04:05"),
		"customers_update_time":      customers.UpdateTime.Format("2006-01-02 15:04:05"),
		"customer_describe":          customers.CustomerDescribe,
		"legal_person":               customers.LegalPerson,
		"customers_num":              customers.CustomersNum,
		"customer_rank":              customers.CustomerRank,
		"drain_cause":                customers.DrainCause,
		"service_describe":           service.ServiceDescribe,
		"create_time":                service.CreateTime.Format("2006-01-02 15:04:05"),
	}
	return respInfo
}
